package threads.demo01;

import java.util.concurrent.TimeUnit;

public class WhileTrueDemo {
    public static void main(String[] args) throws InterruptedException {
        PrintString p = new PrintString();
        p.print();


        // main 线程一直出于死循环，导致下面的代码得不到执行
        System.out.println("准备结束打印");
        p.setContinuePrint(false);
    }
}


class PrintString {

    private boolean isContinuePrint = true;

    public void setContinuePrint(boolean continuePrint) {
        isContinuePrint = continuePrint;
    }

    public void print() throws InterruptedException {
        while(isContinuePrint){
            System.out.println(Thread.currentThread() + " run ...");
            TimeUnit.SECONDS.sleep(1);
        }
    }
}